import static com.googlecode.javacv.jna.highgui.cvLoadImage;
import static com.googlecode.javacv.jna.highgui.cvSaveImage;
import static com.googlecode.javacv.jna.cxcore.cvReleaseImage;
import static com.googlecode.javacv.jna.cv.CV_GAUSSIAN;
import static com.googlecode.javacv.jna.cv.cvSmooth;
import static com.googlecode.javacv.jna.cxcore.IPL_DEPTH_8U;

import java.io.File;

import com.googlecode.javacv.cpp.opencv_core.IplImage;


public class CvTest
{
        private IplImage src, dst;
       
        public CvTest(String filename) {
                File imageFile = new File(filename);
                if(!imageFile.exists()) {
                        throw new RuntimeException("Image file " + filename + " not found.");
                }
                this.src = cvLoadImage(filename);
                this.dst = IplImage.create(cxcore.cvGetSize(src), IPL_DEPTH_8U, 3);
        }
       
        public void smoothImage() {
                cvSmooth(this.src, this.dst, CV_GAUSSIAN, 11, 11, 0.2f, 0.1f);
                cvSaveImage("newCloud.jpg", dst);
                //cxcore.cvReleaseData(src);
                //cxcore.cvReleaseData(dst);
        }

        public static void main(String[] args)
        {
                if(args.length != 1) {
                        System.err.println("Usage: CvTest filename");
                        return;
                }
                else {
                        CvTest imageProcessor = new CvTest(args[0]);
                        imageProcessor.smoothImage();
                        System.out.print("\n Program terminated normally. \n");
                }
        }
}

